# 1. Flask-Ecrpyt, Used for secret the password
from flask_bcrypt import Bcrypt

bcrypt = Bcrypt()

# 2. LoginManager, Userd for login and logout
from flask_login import LoginManager

login_manager = LoginManager()

#: Redirect to this page  when @login_required
login_manager.login_view = "main.login"

#: Set more stronger auth-protection
login_manager.session_protection = "strong"

#: Show information when logging
login_manager.login_message = u"Please login ..."

#: Set the Login Messages type as `information`
login_manager.login_message_category = "info"


@login_manager.user_loader
def load_user(user_id):
	""" 
	Load the user's info 
	
	Called when user calling `login_user()` that find the user base on `usesr_id` 
	"""
	
	from blog.models import User
	
	return User.query.filter_by(id=user_id).first()


# 3. OpenID : do not understand
from flask_openid import OpenID

openid = OpenID()

# 4. Principal
from flask_principal import Principal, Permission, RoleNeed

principals = Principal()

#: RoleNeed ,UserNeed just a named tuple of a required need
admin_permission = Permission(RoleNeed('admin'))
poster_permission = Permission(RoleNeed('poster'))
default_permission = Permission(RoleNeed('default'))

# 5. Celery, Used to Async task
from flask_celery import Celery

flask_celery = Celery()

# 6. flask_admin, Userd for manage back-end(后台)
from flask_admin import Admin

flask_admin = Admin(name='后台管理系统')
